const Koa = require('koa')
const serve = require('koa-static');
const { historyApiFallback } = require('koa2-connect-history-api-fallback')
const proxy = require('koa2-proxy-middleware')
const app = new Koa();

const path = require('path')
app.use(historyApiFallback({ 
    whiteList: ['/prod-api']
})); 
app.use(proxy({
    targets: {
      // (.*) means anything
      '/prod-api/(.*)': {
          target: 'http://localhost:3000', //后端服务器地址
          changeOrigin: true,
          pathRewrite: { 	
              '/prod-api': "/api"
          }
      }
    }
  }))

app.use(serve(__dirname + "/public"));
app.listen(3333, () => {
    console.log('服务器已启动: http://localhost:3333');
})